package com.mzj.saas.mservice.propertybill.controller;

import com.mzj.saas.annotation.RepeatSubmit;
import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.bill.vo.BillSearchRequestVO;
import com.mzj.saas.mservice.bill.vo.PaymentOrderApiData;
import com.mzj.saas.mservice.property.vo.BillListVo;
import com.mzj.saas.mservice.property.vo.HouseRemainingRecordVo;
import com.mzj.saas.mservice.property.vo.ReturnDetailsVo;
import com.mzj.saas.mservice.propertybill.service.AccountManageService;
import com.mzj.saas.mservice.propertybill.vo.*;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 非公租房-账户管理
 */
@Controller
@RequestMapping("/account")
@Api(tags = "账户管理")
public class AccountManageController {

    @Autowired
    private AccountManageService accountManageService;

    /**
     * 账单列表-首页
     *
     * @return
     */
    @PostMapping(value = "aggregateData")
    @ResponseBody
    @ApiOperation(notes = "首页", value = "首页数据")
    public ResultBean<AggregateDataVo> billListShow(@RequestHeader String accessToken, @RequestBody AggregateDataVo vo) {
        return accountManageService.aggregateData(accessToken, vo);
    }


    /**
     * 账单列表-账单调整
     *
     * @return
     */
    @PostMapping(value = "billAdjust")
    @ResponseBody
    @ApiOperation(notes = "账单调整", value = "账单调整")
    public ResultBean<Object> billAdjust(@RequestHeader String accessToken, @RequestBody BillAdjustVo vo) {
        return accountManageService.billAdjust(accessToken, vo);
    }

    /**
     * 账户管理-个人承租人管理/单位承租人管理
     *
     * @param accessToken
     * @param pageNumber
     * @param pageSize
     * @param =
     * @return
     */
    @GetMapping(value = "accountList")
    @ResponseBody
    @ApiOperation("账户管理-个人承租人管理/单位承租人管理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "residenceCommunityId", value = "小区id", required = false),
            @ApiImplicitParam(name = "buildingNum", value = "楼宇", required = false),
            @ApiImplicitParam(name = "unit", value = "单元", required = false),
            @ApiImplicitParam(name = "roomNumber", value = "房号", required = false),
            @ApiImplicitParam(name = "name", value = "承租人名", required = false),
            @ApiImplicitParam(name = "status", value = "账户状态", required = false),
            @ApiImplicitParam(name = "orgId", value = "机构id", required = true),
            @ApiImplicitParam(name = "accountType", value = "账户类型 0个人承租人  1单位承租人", required = true)
    })
    public ResultBean<ApiData<RemainingAccountVo>> accountList(@RequestHeader String accessToken,
                                                               @RequestParam(required = false) String residenceCommunityId,
                                                               @RequestParam(required = false) Long buildingNum,
                                                               @RequestParam(required = false) Long unit,
                                                               @RequestParam(required = false) String roomNumber,
                                                               @RequestParam(required = false) String name,
                                                               @RequestParam(required = false) Integer status,
                                                               @RequestParam(required = false) Long orgId,
                                                               @RequestParam(required = false) Integer accountType,
                                                               @RequestParam(defaultValue = "0") Integer pageNumber,
                                                               @RequestParam(defaultValue = "5") Integer pageSize
    ) {
        return accountManageService.accountList
                (accessToken, pageNumber, pageSize, residenceCommunityId, buildingNum, unit, roomNumber, name, status, orgId, accountType);
    }

    /**
     *个人承租人管理/单位承租人 账户动账明细
     * @param accessToken
     * @return
     */
    @GetMapping(value = "/listRemainingRecord")
    @ResponseBody
    @ApiOperation("账户管理-个人承租人管理/单位承租人管理-账户动账明细")
    public ResultBean<ApiData<HouseRemainingRecordVo>> listRemainingRecord(@RequestHeader String accessToken,
                                                                   @ApiParam("余额id") @RequestParam Long remId,
                                                                   @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                   @RequestParam(defaultValue = "5") Integer pageSize
    ) {
        return accountManageService.listRemainingRecord
                (accessToken, pageNumber, pageSize,remId);
    }



    /**
     *  账户管理-单位账户列表
     *
     */
    @GetMapping(value = "depRemainingList")
    @ResponseBody
    @ApiOperation(notes = "单位账户列表", value = "单位账户列表")
    public ResultBean<ApiData<DepRemainingVo>> depRemainingList(@RequestHeader String accessToken, @ApiParam("机构名") @RequestParam String depName,
                                                                @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                @RequestParam(defaultValue = "10") Integer pageSize) {
        return accountManageService.depRemainingList(accessToken, depName,pageNumber,pageSize);
    }

    /**
     *  账户管理-单位账户详情列表
     *
     */
    @GetMapping(value = "depRemainingHouseList")
    @ResponseBody
    @ApiOperation(notes = "单位账户详情列表", value = "单位账户详情列表")
    public ResultBean<ApiData<DepRemainingHouseVo>> depRemainingHouseList(@RequestHeader String accessToken,
                                                                          @ApiParam("小区")@RequestParam(required = false) String communityId,
                                                                          @ApiParam("楼栋")@RequestParam(required = false) Long buildingNum,
                                                                          @ApiParam("单元")@RequestParam(required = false) Long unit,
                                                                          @ApiParam("房号")@RequestParam(required = false) String roomNumber,
                                                                          @ApiParam(value = "余额id",required = true)@RequestParam Long depRemainingId,
                                                                     @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                     @RequestParam(defaultValue = "10") Integer pageSize) {
        return accountManageService.depRemainingHouseList(accessToken, communityId,buildingNum,unit,roomNumber,pageNumber,pageSize,depRemainingId);
    }
    /**
     *  账户管理-单位账户缴费详情
     *
     */
    @GetMapping(value = "depRemainingPay")
    @ResponseBody
    @ApiOperation(notes = "单位账户缴费详情", value = "单位账户缴费详情")
    public ResultBean<PaymentOrderApiData<DepRemainingRecordVo>> depRemainingPay(@RequestHeader String accessToken,
                                                                     @ApiParam("余额id") @RequestParam Long remainingId,
                                                                     @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                     @RequestParam(defaultValue = "10") Integer pageSize) {
        return accountManageService.depRemainingPay(accessToken,pageNumber,pageSize,remainingId);
    }



    /**
     *  账户管理-单位房产账单代扣更改
     *
     */
    @PostMapping(value = "depRemainingUpdateStatus")
    @ResponseBody
    @ApiOperation(notes = "单位房产账单代扣更改", value = "单位房产账单代扣更改")
    public ResultBean<Object> depRemainingUpdateStatus(@RequestHeader String accessToken,
                                                       @RequestBody DepRemainingHouseVo vo) {
        return accountManageService.depRemainingUpdateStatus(accessToken, vo);
    }
    /**
     *  账户管理-单位房产账单代扣明细
     *
     */
    @GetMapping(value = "depRemainingHouseBill")
    @ResponseBody
    @ApiOperation(notes = "单位房产账单代扣明细", value = "单位房产账单代扣明细")
    public ResultBean<ApiData<BillListVo>> depRemainingHouseBill(@RequestHeader String accessToken,
                                                                            @ApiParam("单位房产关联信息id")@RequestParam  Long depRemainingRefId) {
        return accountManageService.depRemainingHouseBill(accessToken, depRemainingRefId);
    }


    /**
     * 账单列表-调整账单列表
     *
     * @param accessToken
     * @param pageNumber
     * @param pageSize
     * @param type        0调整账单
     * @param filter
     * @return
     */
    @GetMapping(value = "otherBills")
    @ResponseBody
    @ApiOperation(notes = "调整账单列表", value = "调整账单列表")
    public ResultBean<Object> billListShow(@RequestHeader String accessToken,
                                           @RequestParam(defaultValue = "0") Integer pageNumber,
                                           @RequestParam(defaultValue = "10") Integer pageSize,
                                           @RequestParam(name = "type") Integer type,
                                           BillSearchRequestVO filter) {
        return accountManageService.otherBills(accessToken, pageNumber, pageSize, type, filter);
    }

    @GetMapping (value = "otherBillsPay")
    @ResponseBody
    @ApiOperation(notes = "调整账单支付", value = "调整账单支付")
    public ResultBean<Object> otherBillsPay(@RequestHeader String accessToken,
                                           @RequestParam Long billId,
                                           @RequestParam Integer chargeType) {
        return accountManageService.otherBillsPay(accessToken, billId, chargeType);
    }

    /**
     * 账单列表-违约金列表
     *
     * @param accessToken
     * @param pageNumber
     * @param pageSize
     * @param filter
     * @return
     */
    @GetMapping(value = "penalSumList")
    @ResponseBody
    @ApiOperation(notes = "违约金列表", value = "违约金列表")
    public ResultBean<ApiData<PenalSumVO>> penalSumList(@RequestHeader String accessToken,
                                           @RequestParam(defaultValue = "0") Integer pageNumber,
                                           @RequestParam(defaultValue = "10") Integer pageSize,
                                           BillSearchRequestVO filter) {
        return accountManageService.penalSumList(accessToken, pageNumber, pageSize, filter);
    }
    /**
     * 账单列表 - 违约金减免
     *
     * @param accessToken
     * @param violateId
     * @return
     */
    @GetMapping(value = "penalSumMitigate")
    @ResponseBody
    @ApiOperation(notes = "违约金减免", value = "违约金减免")
    public ResultBean<Object> penalSumMitigate(@RequestHeader String accessToken,
                                           @ApiParam(value = "违约金id",required = true)@RequestParam Long violateId) {
        return accountManageService.penalSumMitigate(accessToken, violateId);
    }

    /**
     * 账户管理-缴费凭证管理 凭证列表
     *
     * @param accessToken
     * @param pageNumber
     * @param pageSize
     * @param =
     * @return
     */
    @GetMapping(value = "paymentVoucherList")
    @ResponseBody
    @ApiOperation("账户管理-缴费凭证管理 凭证列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "residenceCommunityId", value = "小区id", required = false),
            @ApiImplicitParam(name = "buildingNum", value = "楼宇", required = false),
            @ApiImplicitParam(name = "unit", value = "单元", required = false),
            @ApiImplicitParam(name = "roomNumber", value = "房号", required = false),
            @ApiImplicitParam(name = "name", value = "承租人名", required = false),
            @ApiImplicitParam(name = "status", value = "缴费凭证状态  0全部 1未审核 2已通过 3未通过", required = false),
            @ApiImplicitParam(name = "accountType", value = "账户类型： 0房屋账户 1单位账户", required = false),
            @ApiImplicitParam(name = "orgId", value = "机构id", required = true)
    })
    public ResultBean<ApiData<PaymentVoucherVo>> paymentVoucherList(@RequestHeader String accessToken,
                                                                    @RequestParam(required = false) String residenceCommunityId,
                                                                    @RequestParam(required = false) Long buildingNum,
                                                                    @RequestParam(required = false) Long unit,
                                                                    @RequestParam(required = false) String roomNumber,
                                                                    @RequestParam(required = false) String name,
                                                                    @RequestParam(required = false) Integer status,
                                                                    @RequestParam(required = false) Long orgId,
                                                                    @RequestParam(required = false) Long accountType,
                                                                    @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                    @RequestParam(defaultValue = "5") Integer pageSize
    ) {
        return accountManageService.paymentVoucherList
                (accessToken, pageNumber, pageSize, residenceCommunityId, buildingNum, unit, roomNumber, name, status, orgId,accountType);
    }

    /**
     * 账户管理-缴费凭证管理 缴费凭证审核d
     *
     * @param accessToken
     * @return
     */
    @GetMapping(value = "voucherAudit")
    @ResponseBody
    @ApiOperation("账户管理-缴费凭证管理 缴费凭证审核")
    @RepeatSubmit
    public ResultBean<Object> voucherAudit(@RequestHeader String accessToken,
                                           @ApiParam(name = "status", value = "审核类型 0通过 1不通过")
                                           @RequestParam(required = false) Integer status,
                                           @ApiParam(name = "voucherIds", value = "凭证id")
                                           @RequestParam List<Long> voucherIds
    ) {
        return accountManageService.voucherAudit(accessToken, status, voucherIds);
    }

    /**
     * 账户管理-缴费凭证管理 缴费凭证提交
     *
     * @param accessToken
     * @return
     */
    @PostMapping(value = "addVoucher")
    @ResponseBody
    @ApiOperation("账户管理-缴费凭证管理 缴费凭证提交")
    public ResultBean<Object> addVoucher(@RequestHeader String accessToken,
                                         @RequestBody VoucherVo vo) {
        return accountManageService.addVoucher(accessToken, vo);
    }


    /**
     * 账户管理-个人承租人/单位承租人 缴费记录明细
     *
     * @param accessToken
     * @param pageNumber
     * @param pageSize
     * @param =
     * @return
     */
    @GetMapping(value = "paymentRecords")
    @ResponseBody
    @ApiOperation("账户管理-个人承租人/单位承租人 缴费记录明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "houseId", value = "房产id", required = true),
            @ApiImplicitParam(name = "communityId", value = "小区id", required = false),
            @ApiImplicitParam(name = "buildingNum", value = "楼宇", required = false),
            @ApiImplicitParam(name = "unit", value = "单元", required = false),
            @ApiImplicitParam(name = "roomNumber", value = "房号", required = false),
            @ApiImplicitParam(name = "name", value = "承租人名", required = false),
            @ApiImplicitParam(name = "orgId", value = "机构id", required = true),
            @ApiImplicitParam(name = "accountType", value = "账户类型 0个人承租人  1单位承租人", required = true)
    })
    public ResultBean<PaymentOrderApiData<PaymentRecordVo>> paymentRecords(@RequestHeader String accessToken,
                                                                           @RequestParam(required = false) String houseId,
                                                                           @RequestParam(required = false) Long orgId,
                                                                           @RequestParam(required = false) Integer accountType,
                                                                           @RequestParam(required = false) String communityId,
                                                                           @RequestParam(required = false) Long buildingNum,
                                                                           @RequestParam(required = false) Long unit,
                                                                           @RequestParam(required = false) String roomNumber,
                                                                           @RequestParam(required = false) String name,
                                                                           @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                           @RequestParam(defaultValue = "5") Integer pageSize
    ) {
        return accountManageService.paymentRecords
                (accessToken, pageNumber, pageSize, houseId, orgId, accountType,communityId,buildingNum,unit,roomNumber,name);
    }


    /**
     * 退租管理-以退租列表
     *
     * @return
     */
    /*@GetMapping(value = "retiredLeaseList")
    @ApiOperation(notes = "退租列表", value = "退租列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "residenceCommunityId", value = "小区id", required = false),
            @ApiImplicitParam(name = "buildingNum", value = "楼宇", required = false),
            @ApiImplicitParam(name = "unit", value = "单元", required = false),
            @ApiImplicitParam(name = "roomNumber", value = "房号", required = false),
            @ApiImplicitParam(name = "name", value = "承租人名", required = false),
            @ApiImplicitParam(name = "refundStatus", value = "退费状态  0未退款 1已退款", required = false)
    })
    @ResponseBody
    public ResultBean<ApiData<RetiredVo>> retiredLeaseList(@RequestHeader String accessToken,
                                               @RequestParam(required = false) String residenceCommunityId,
                                               @RequestParam(required = false) Long buildingNum,
                                               @RequestParam(required = false) Long unit,
                                               @RequestParam(required = false) String roomNumber,
                                               @RequestParam(required = false) String name,
                                               @RequestParam(defaultValue = "0") Integer pageNumber,
                                               @RequestParam(defaultValue = "5") Integer pageSize,
                                               @RequestParam(required = false) Long refundStatus) {
        return accountManageService.retiredLeaseList
                (accessToken, residenceCommunityId, buildingNum, unit, roomNumber, name, pageNumber, pageSize, refundStatus);
    }*/
    /**
     * 退费记录
     *
     * @return
     */
    @GetMapping(value = "returnList")
    @ApiOperation(notes = "退费记录", value = "退费记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "residenceCommunityId", value = "小区id", required = false),
            @ApiImplicitParam(name = "buildingNum", value = "楼宇", required = false),
            @ApiImplicitParam(name = "unit", value = "单元", required = false),
            @ApiImplicitParam(name = "roomNumber", value = "房号", required = false),
            @ApiImplicitParam(name = "name", value = "承租人名", required = false),
            @ApiImplicitParam(name = "type", value = "类型：0退款 1补缴", required = false),
            @ApiImplicitParam(name = "paymentStatus", value = "缴费状态：0未处理 1已处理", required = false)
    })
    @ResponseBody
    public ResultBean<ApiData<RetiredVo>> returnList(@RequestHeader String accessToken,
                                               @RequestParam(required = false) String residenceCommunityId,
                                               @RequestParam(required = false) Long buildingNum,
                                               @RequestParam(required = false) Long unit,
                                               @RequestParam(required = false) String roomNumber,
                                               @RequestParam(required = false) String name,
                                               @RequestParam(required = false) Integer type,
                                               @RequestParam(defaultValue = "0") Integer pageNumber,
                                               @RequestParam(defaultValue = "5") Integer pageSize,
                                               @RequestParam(required = false) Integer paymentStatus) {
        return accountManageService.returnList
                (accessToken, residenceCommunityId, buildingNum, unit, roomNumber, name, pageNumber, pageSize, paymentStatus,type);
    }

    /**
     * 退费记录-详情
     *
     * @return
     */
    @GetMapping(value = "returnParticulars")
    @ApiOperation(notes = "退费记录-详情", value = "退费记录-详情")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "returnId", value = "退费记录id", required = true)
    )
    @ResponseBody
    public ResultBean<ReturnDetailsVo> returnParticulars(@RequestHeader String accessToken, @RequestParam Long returnId) {
        return accountManageService.returnParticulars(accessToken, returnId);
    }


    /**
     * 退费记录-退款
     *
     * @return
     */
    @GetMapping(value = "refund")
    @ApiOperation(notes = "退费记录-退款", value = "退费记录-退款")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "returnId", value = "退费id", required = true)
    )
    @ResponseBody
    public ResultBean<Object> refund(@RequestHeader String accessToken, @RequestParam Long returnId) {
        return accountManageService.refund(accessToken, returnId);
    }

    /**
     * 数据记录-延期记录
     *
     * @return
     */
    @GetMapping(value = "postponeList")
    @ApiOperation(notes = "延期记录", value = "延期记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "residenceCommunityId", value = "小区id", required = false),
            @ApiImplicitParam(name = "buildingNum", value = "楼宇", required = false),
            @ApiImplicitParam(name = "unit", value = "单元", required = false),
            @ApiImplicitParam(name = "roomNumber", value = "房号", required = false),
            @ApiImplicitParam(name = "houseId", value = "房屋id", required = false),
            @ApiImplicitParam(name = "name", value = "承租人名", required = false),
            @ApiImplicitParam(name = "postponeType", value = "延期状态  0延期 1取消延期")
    })
    @ResponseBody
    public ResultBean<ApiData<PostponeVo>> postponeList(@RequestHeader String accessToken,
                                           @RequestParam(required = false) String residenceCommunityId,
                                           @RequestParam(required = false) Long buildingNum,
                                           @RequestParam(required = false) Long unit,
                                           @RequestParam(required = false) String roomNumber,
                                           @RequestParam(required = false) String houseId,
                                           @RequestParam(required = false) String name,
                                           @RequestParam(defaultValue = "0") Integer pageNumber,
                                           @RequestParam(defaultValue = "5") Integer pageSize,
                                           @RequestParam(required = false) Integer postponeType) {
        return accountManageService.postponeList
                (accessToken, residenceCommunityId, buildingNum, unit, roomNumber,houseId, name, pageNumber, pageSize, postponeType);
    }
    /**
     * 数据记录-延期记录-取消延期
     * @return
     */
    @GetMapping(value = "cancelPostpone")
    @ApiOperation(notes = "延期记录-取消延期", value = "延期记录-取消延期")
    @RepeatSubmit
    @ResponseBody
    public ResultBean<Object> cancelPostpone(@RequestHeader String accessToken,
                                             @ApiParam(value = "余额账户id",required = true)@RequestParam Long remainingId,
                                             @ApiParam(value = "延期记录id",required = true)@RequestParam Long postponeId,
                                             @ApiParam(value = "取消原因",required = true)@RequestParam String cause) {
        return accountManageService.cancelPostpone(accessToken,remainingId,cause,postponeId);
    }

    /**
     * 延期记录-取消延期-详情
     * @param accessToken
     * @param remPostponeId
     * @return
     */
    @GetMapping(value = "/postponeParticulars")
    @ApiOperation(notes = "延期记录-取消延期-详情", value = "延期记录-取消延期-详情")
    @ResponseBody
    public ResultBean<PostponeVo> postponeParticulars(@RequestHeader String accessToken,
                                             @ApiParam(value = "延期记录id",required = true)@RequestParam Long remPostponeId) {
        return accountManageService.postponeParticulars(accessToken,remPostponeId);
    }



    /**
     * 审核人设置-审核人列表
     *
     * @return
     */
    @GetMapping(value = "auditorList")
    @ApiOperation(notes = "审核人列表", value = "审核人列表")
    @ResponseBody
    public ResultBean<ApiData<AuditorVo>> auditorList(@RequestHeader String accessToken,
                                          @ApiParam(value = "机构id",required = true) @RequestParam Long orgId,
                                          @ApiParam(value = "审核人类型 0账单审核  1缴费凭证审核",required = false) @RequestParam(required = false) Integer type) {
        return accountManageService.auditorList(accessToken,orgId,type);
    }
    /**
     * 审核人设置-审核人 新增
     *
     * @return
     */
    @PostMapping(value = "addAuditor")
    @ApiOperation(notes = "审核人 新增", value = "审核人  新增")
    @ResponseBody
    public ResultBean<ApiData<AuditorVo>> addAuditor(@RequestHeader String accessToken, @RequestBody  AuditorApi vo) {
        return accountManageService.addAuditor(accessToken,vo);
    }

    /**
     * 审核人设置-删除审核人
     *
     * @return
     */
    @PostMapping(value = "deleteAuditor")
    @ApiOperation(notes = "审核人 删除", value = "审核人  删除")
    @ResponseBody
    public ResultBean<Object> deleteAuditor(@RequestHeader String accessToken, @RequestBody  AuditorApi vo) {
        return accountManageService.deleteAuditor(accessToken,vo);
    }




}
